package model

import (
	"nspel/entity"
)

type PostLoginRes struct {
	RetCode      int64  `json:"retCode"`
	Name         string `json:"name"`
	Introduction string `json:"introduction"`
	Role         string `json:"role"`
}

func (userInfo *PostLoginRes) GetUserInfo(authority byte, userId int64, userName string) (err error) {
	userInfo.RetCode = 0
	if authority == entity.ManagerAuthority.Administrator {
		userInfo.Role = "admin"
		userInfo.Name = userName
		userInfo.Introduction = "超级管理员"
	} else if authority == entity.ManagerAuthority.Province {
		userInfo.Role = "province"
		userInfo.Name = userName
		userInfo.Introduction = "省管理员"
	} else if authority == entity.ManagerAuthority.City {
		userInfo.Role = "city"
		userInfo.Name = userName
		userInfo.Introduction = "市管理员"
	} else if authority == entity.ManagerAuthority.Area {
		userInfo.Role = "area"
		area := new(entity.Area)
		err = area.SelectAllByUserId(userId)
		if err != nil {
			return
		}
		if area.Contact.Valid {
			userInfo.Name = area.Contact.String
		} else {
			userInfo.Name = userName
		}
		userInfo.Introduction = area.Name + "管理员"
	} else if authority == entity.ManagerAuthority.School {
		userInfo.Role = "school"
		school := new(entity.School)
		err = school.SelectAllByUserId(userId)
		if err != nil {
			return
		}
		if school.Contact.Valid {
			userInfo.Name = school.Contact.String
		} else {
			userInfo.Name = userName
		}
		userInfo.Introduction = school.Name + "管理员"
	}
	return
}

type GetManagerListRes struct {
	RetCode int64         `json:"retCode"`
	Total   int64         `json:"total"`
	Data    []ManagerList `json:"data"`
}

type ManagerList struct {
	Id        int64  `json:"id"`
	UserName  string `json:"userName"`
	Authority string `json:"authority"`
	Object    string `json:"object"`
	Name      string `json:"name"`
}
